package com.ljx.itbbs.server.user.dao;

import com.ljx.itbbs.common.domain.enums.CommonStatusEnum;
import com.ljx.itbbs.server.user.domain.entity.MenuEntity;
import com.ljx.itbbs.server.user.domain.enums.MenuParentEnum;
import com.ljx.itbbs.server.user.domain.vo.req.MenuUpdateReq;
import com.ljx.itbbs.server.user.domain.vo.resp.MenuResp;
import com.ljx.itbbs.server.user.mapper.MenuMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author LiJunXi
 * @since 2024-03-02
 */
@Service
public class MenuDao extends ServiceImpl<MenuMapper, MenuEntity> {

    public List<MenuResp> getUserMenuList(Long userId) {
        return this.baseMapper.getUserMenuList(userId);
    }

    public List<MenuEntity> getParentMenu() {
        return lambdaQuery()
                .eq(MenuEntity::getParentId, MenuParentEnum.PARENT.getId())
                .eq(MenuEntity::getStatus, CommonStatusEnum.NORMAL.getStatus())
                .list();
    }

    public void updateMenu(MenuUpdateReq req) {
        lambdaUpdate().set(MenuEntity::getParentId, req.getParentId())
                .set(MenuEntity::getSort, req.getSort())
                .set(MenuEntity::getName, req.getName())
                .set(MenuEntity::getTitle, req.getTitle())
                .set(MenuEntity::getHidden, req.getHidden())
                .set(MenuEntity::getIcon, req.getIcon())
                .set(MenuEntity::getStatus, req.getStatus())
                .eq(MenuEntity::getId, req.getId())
                .update();
    }
}
